<template>
	<view class="login">
		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体表单 -->
			<view class="main">
				<wInput
					v-model="phoneData"
					type="text"
					maxlength="11"
					placeholder="用户名/电话"
					:focus="isFocus"
				></wInput>
				<wInput
					v-model="passData"
					type="password"
					maxlength="11"
					placeholder="密码"
				></wInput>
			</view>
			<wButton 
				class="wbutton"
				text="登 录"
				:rotate="isRotate" 
				style="margin: 60px auto;"
				@click="startLogin"
			></wButton>
			
			<!-- 其他登录 -->
			<view class="other_login cuIcon">
				<view class="login_icon">
					<view class="cuIcon-weixin" @tap="login_weixin"></view>
				</view>
				<view class="login_icon">
					<view class="cuIcon-warnfill" @tap="login_phone"></view>
				</view>
				<view class="login_icon">
					<view class="cuIcon-github" @tap="login_github"></view>
				</view>
			</view>
			
			<!-- 底部信息 -->
			<view class="footer">
				<navigator url="forget" open-type="navigate">找回密码</navigator>
				<text>|</text>
				<navigator url="register" open-type="navigate">注册账号</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require('../../common/util.js');
	let _this;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	
	export default {
		data() {
			return {
				//logo图片 base64
				logoImage: '',
				phoneData:'', //用户/电话
				passData:'', //密码
				isRotate: false, //是否加载旋转
				isFocus: true // 是否聚焦
			};
		},
		components:{
			wInput,
			wButton,
		},
		mounted() {
			_this= this;
			//this.isLogin();
		},
		methods: {
		    startLogin(e){
                console.log(e)
				//登录
				if(this.isRotate){
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.phoneData.length == "") {
				    this.$u.toast('请输入用户名');
				    return;
				}
		        if (this.passData.length < 3) {
		            this.$u.toast('密码不正确');
		            return;
		        }
				_this.isRotate=true
				setTimeout(function(){
					_this.isRotate=false
				},3000)
				this.login_username(this.phoneData,this.passData)
				
		    },
			login_username(username,password){
				let _this = this;
				const param = {'username':username,'password':password}
				util.requestPost('Envlogin/abc',param,function(res) {
					if(res.code == 1){
						uni.setStorageSync('utoken',res.data.list.utoken_return)
						_this.$u.toast(res.msg, 2000);
						setTimeout(function(){
							uni.navigateTo({
								url:'/pages/tab/tab?tab=index'
							})
						},3000)
					}else{
						_this.$u.toast(res.msg, 2000);
						_this.isRotate=false
					}
				}, (err) => {
					console.log(err);
				}, {isShowLoading: false});
			},
			login_weixin() {
				//微信登录
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
				    console.log(loginRes.authResult);
				  }
				});
			},
			login_phone() {
				//运营商登录
				uni.getProvider({
				    service: 'oauth',
				    success: function (res) {
				        console.log(res.provider)// ['qq', 'univerify']
				    }
				});
			},
			login_github() {
				//github登录
				this.$u.toast('github', 2000);
			}
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
